namespace QuickPrompt.DataAccess.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class InitialSchema : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "dbo.Prompt",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        AddressValue = c.String(nullable: false, maxLength: 8000, unicode: false),
                        NoteId = c.Int(nullable: false),
                        PromptType = c.Int(nullable: false),
                        PromptTimeZone = c.String(nullable: false, maxLength: 8000, unicode: false),
                        PromptFrequency = c.Int(nullable: false),
                        StartingFromUtc = c.DateTime(nullable: false, precision: 7, storeType: "datetime2"),
                        LastPromptedUtc = c.DateTime(precision: 7, storeType: "datetime2"),
                        DateCreatedUtc = c.DateTime(nullable: false, precision: 7, storeType: "datetime2"),
                        LastUpdatedUtc = c.DateTime(nullable: false, precision: 7, storeType: "datetime2"),
                        UpdatedByUserId = c.Int(),
                        LastActivityIpAddress = c.String(maxLength: 8000, unicode: false),
                        IsActive = c.Boolean(nullable: false),
                        IsDeleted = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.QuickNote", t => t.NoteId, cascadeDelete: true)
                .Index(t => new { t.NoteId, t.PromptFrequency, t.AddressValue }, unique: true, name: "IX_PromptByNote");
            
            CreateTable(
                "dbo.QuickNote",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        Name = c.String(nullable: false, maxLength: 150, unicode: false),
                        Description = c.String(maxLength: 500, unicode: false),
                        StartDateUtc = c.DateTime(nullable: false, precision: 7, storeType: "datetime2"),
                        EndDateUtc = c.DateTime(nullable: false, precision: 7, storeType: "datetime2"),
                        UserGuid = c.String(nullable: false, maxLength: 128, unicode: false),
                        DateCreatedUtc = c.DateTime(nullable: false, precision: 7, storeType: "datetime2"),
                        IsActive = c.Boolean(nullable: false),
                        LastUpdatedUtc = c.DateTime(nullable: false, precision: 7, storeType: "datetime2"),
                        UpdatedByUserId = c.Int(),
                        LastActivityIpAddress = c.String(maxLength: 8000, unicode: false),
                        IsDeleted = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.User", t => t.UserGuid, cascadeDelete: true)
                .Index(t => t.Name, unique: true, name: "IX_QuickNoteByUser")
                .Index(t => t.UserGuid);
            
            CreateTable(
                "dbo.User",
                c => new
                    {
                        UserGuid = c.String(nullable: false, maxLength: 128, unicode: false),
                        FirstName = c.String(maxLength: 50, unicode: false),
                        LastName = c.String(maxLength: 50, unicode: false),
                        UserName = c.String(nullable: false, maxLength: 256, unicode: false),
                        PasswordHash = c.String(maxLength: 8000, unicode: false),
                        PasswordSalt = c.String(maxLength: 8000, unicode: false),
                        Locked = c.Boolean(),
                        IsAdmin = c.Int(),
                        RegisteredIpAddress = c.String(maxLength: 8000, unicode: false),
                        Email = c.String(maxLength: 256, unicode: false),
                        EmailConfirmed = c.Boolean(nullable: false),
                        SecurityStamp = c.String(maxLength: 8000, unicode: false),
                        PhoneNumber = c.String(maxLength: 8000, unicode: false),
                        PhoneNumberConfirmed = c.Boolean(nullable: false),
                        TwoFactorEnabled = c.Boolean(nullable: false),
                        LockoutEndDateUtc = c.DateTime(precision: 7, storeType: "datetime2"),
                        LockoutEnabled = c.Boolean(nullable: false),
                        AccessFailedCount = c.Int(nullable: false),
                        DateCreatedUtc = c.DateTime(precision: 7, storeType: "datetime2"),
                        LastUpdatedUtc = c.DateTime(precision: 7, storeType: "datetime2"),
                        UpdatedByUserId = c.Int(),
                        LastActivityIpAddress = c.String(maxLength: 8000, unicode: false),
                        IsActive = c.Boolean(),
                        IsDeleted = c.Boolean(),
                        Discriminator = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => t.UserGuid)
                .Index(t => t.UserName, unique: true)
                .Index(t => t.UserName, unique: true, name: "UserNameIndex");
            
            CreateTable(
                "dbo.UserClaim",
                c => new
                    {
                        Id = c.Int(nullable: false, identity: true),
                        UserId = c.String(nullable: false, maxLength: 128, unicode: false),
                        ClaimType = c.String(maxLength: 8000, unicode: false),
                        ClaimValue = c.String(maxLength: 8000, unicode: false),
                        Discriminator = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => t.Id)
                .ForeignKey("dbo.User", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.UserLogin",
                c => new
                    {
                        LoginProvider = c.String(nullable: false, maxLength: 128, unicode: false),
                        ProviderKey = c.String(nullable: false, maxLength: 128, unicode: false),
                        UserId = c.String(nullable: false, maxLength: 128, unicode: false),
                        Discriminator = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => new { t.LoginProvider, t.ProviderKey, t.UserId })
                .ForeignKey("dbo.User", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId);
            
            CreateTable(
                "dbo.UserRole",
                c => new
                    {
                        UserId = c.String(nullable: false, maxLength: 128, unicode: false),
                        RoleId = c.String(nullable: false, maxLength: 128, unicode: false),
                        Discriminator = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => new { t.UserId, t.RoleId })
                .ForeignKey("dbo.Role", t => t.RoleId, cascadeDelete: true)
                .ForeignKey("dbo.User", t => t.UserId, cascadeDelete: true)
                .Index(t => t.UserId)
                .Index(t => t.RoleId);
            
            CreateTable(
                "dbo.Role",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 128, unicode: false),
                        Name = c.String(nullable: false, maxLength: 256, unicode: false),
                        Description = c.String(maxLength: 8000, unicode: false),
                        Discriminator = c.String(nullable: false, maxLength: 128),
                    })
                .PrimaryKey(t => t.Id)
                .Index(t => t.Name, unique: true, name: "RoleNameIndex");
            
        }
        
        public override void Down()
        {
            DropForeignKey("dbo.UserRole", "UserId", "dbo.User");
            DropForeignKey("dbo.UserLogin", "UserId", "dbo.User");
            DropForeignKey("dbo.UserClaim", "UserId", "dbo.User");
            DropForeignKey("dbo.UserRole", "RoleId", "dbo.Role");
            DropForeignKey("dbo.QuickNote", "UserGuid", "dbo.User");
            DropForeignKey("dbo.Prompt", "NoteId", "dbo.QuickNote");
            DropIndex("dbo.Role", "RoleNameIndex");
            DropIndex("dbo.UserRole", new[] { "RoleId" });
            DropIndex("dbo.UserRole", new[] { "UserId" });
            DropIndex("dbo.UserLogin", new[] { "UserId" });
            DropIndex("dbo.UserClaim", new[] { "UserId" });
            DropIndex("dbo.User", "UserNameIndex");
            DropIndex("dbo.User", new[] { "UserName" });
            DropIndex("dbo.QuickNote", new[] { "UserGuid" });
            DropIndex("dbo.QuickNote", "IX_QuickNoteByUser");
            DropIndex("dbo.Prompt", "IX_PromptByNote");
            DropTable("dbo.Role");
            DropTable("dbo.UserRole");
            DropTable("dbo.UserLogin");
            DropTable("dbo.UserClaim");
            DropTable("dbo.User");
            DropTable("dbo.QuickNote");
            DropTable("dbo.Prompt");
        }
    }
}
